package com.bl._04delay;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

import java.nio.charset.StandardCharsets;

/**
 *  生产者
 */
public class Producer {

    public static void main(String[] args) throws MQClientException, MQBrokerException, RemotingException, InterruptedException {
        // 1 获取producer对象
        DefaultMQProducer producer = new DefaultMQProducer("delay_product_group");
        // 2 设置nameserver地址链接
        producer.setNamesrvAddr("localhost:9876");
        // 3 启动
        producer.start();
        // 4 创建消息对象，设置消息
        Message message = new Message("delay", "hello", "学个基尔".getBytes(StandardCharsets.UTF_8));



        // 设置延迟消息级别
        message.setDelayTimeLevel(3);

        // 发送延迟消息
        SendResult send = producer.send(message);

        // 4.3.打印消息发送结果
        System.out.println(send);
        // 5 关闭
        producer.shutdown();
    }

}
